<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
    <title>
        <c:if test="${empty(data.id)}">添加人员</c:if>
        <c:if test="${!empty(data.id)}">编辑人员</c:if>
    </title>

    <script type="text/javascript" charset="utf-8" src="${ctx}/static/inspinia/js/plugins/ueditor-1.4.3.3/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="${ctx}/static/inspinia/js/plugins/ueditor-1.4.3.3/_examples/editor_api.js"></script>
    <script type="text/javascript" charset="utf-8" src="${ctx}/static/inspinia/js/plugins/ueditor-1.4.3.3/lang/zh-cn/zh-cn.js"></script>

</head>

<body>

<div id="wrapper">
    <div class="gray-bg">
        <div class="row m-t-sm">
            <div class="col-lg-12">
                <ol class="breadcrumb f-fl">
                    <li>
                        <i class="fa fa-location-arrow"></i><a>${sys_flag ? '人员管理' : '人员信息'}</a>
                    </li>
                    <c:if test="${sys_flag}">
                        <li class="active">
                            <strong>
                                <c:if test="${empty(data.id)}">添加人员</c:if>
                                <c:if test="${!empty(data.id)}">编辑人员</c:if>
                            </strong>
                        </li>
                    </c:if>
                </ol>
                <c:if test="${sys_flag}">
                    <span class="navbar-right  m-r m-t-8"><a href="javascript:history.go(-1);" class="btn-primary btn-add "> <i class='fa fa-mail-reply'></i> 返回</a></span>
                </c:if>
            </div>
        </div>
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox float-e-margins">
                        <c:if test="${type == 0}">
                            <div class="tabs-container">
                                <ul class="nav nav-tabs">
                                    <li class="active"><a  href="javascript:void(0)">基本信息</a></li>
                                    <li class=""><a  href="${ctx}/admin/semRecord/resident/list?id=${data.id}">监测数据</a></li>
                                    <li class=""><a  href="${ctx}/admin/ehm/question/qs/edit?id=${data.id}&type=1">问卷调查</a></li>
                                </ul>
                            </div>
                        </c:if>
                        <div class="ibox-content">
                            <form method="get"
                                  <c:if test="${sys_flag}">data-ajax="${ctx}/admin/ehm/user/list" </c:if>
                                  <c:if test="${!sys_flag}">data-ajax="${ctx}/admin/ehm/user/info/edit" </c:if>
                                  action="${ctx}/admin/ehm/user/save"  class="form-horizontal" id="user_form">
                                <input  type="hidden" id="ids" name="id" value="${data.id}"/>
                                <input  type="hidden" id="uid" name="uid" value="${data.uid}"/>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">图片</label>
                                    <div class="col-sm-2">
                                        <input  type="hidden" id="src" name="image" value="${data.image}"/>
                                        <div class="imager" id="srcView">
                                            <c:choose>
                                                <c:when test="${not empty data.image}">
                                                    <img src="${data.image}" width="100%" height="100%">
                                                </c:when>
                                                <c:otherwise>
                                                    <img src="${ctx}/static/inspinia/img/default_pic_no.jpg" width="100%" height="100%">
                                                </c:otherwise>
                                            </c:choose>
                                        </div>
                                    </div>
                                    <div class="col-sm-3 upload-img-pt25">
                                        <div class="upload f-fl" id="uploaderLogoUrl"></div>
                                        <div class="tip f-fl upload-img-pt10"><span class="upload-img-ml6">建议上传：676*520</span></div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>身份证号</label>
                                    <div class="col-sm-3">
                                        <input id="xmbh" type="text" class="form-control" onBlur="idcards(this.value);" placeholder="身份证号" value="${data.idCard}" name="idCard" required <c:if test="${!sys_flag}">readonly</c:if>>
                                        <span id="userText"></span>
                                    </div>
                                </div>
                                <div class="form-group"><label class="col-sm-2 control-label"><span class="text-danger">*</span>姓名</label>
                                    <div class="col-sm-8"><input type="text" class="form-control" placeholder="请输入人员名称" value="${data.title}" id="title" name="title" required <c:if test="${!sys_flag}">readonly</c:if>></div>
                                </div>


                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>手机号</label>
                                    <div class="col-sm-3"><input type="text" class="form-control" placeholder="请输入手机号" value="${data.cellphone}" name="cellphone" required></div>

                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>性别</label>
                                    <div class="col-sm-3">
                                        <select name="sex" id="sex" class="form-control form-filter"  style="width:100%" required >
                                            <option value="">请选择性别</option>
                                            <option value="1"<c:if test="${data.sex == 1}">selected="true"</c:if>>男</option>
                                            <option value="2"<c:if test="${data.sex == 2}">selected="true"</c:if>>女</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><span class="text-danger"></span>年龄</label>
                                    <div class="col-sm-3"><input type="text" class="form-control" placeholder="请输入年龄" value="${data.age}" id="age" name="age" ></div>

                                    <label class="col-sm-2 control-label"><span class="text-danger"></span>婚姻状态</label>
                                    <div class="col-sm-3">
                                        <select name="marital"  class="form-control form-filter"  style="width:100%">
                                        <option value="">请选择婚姻状态</option>
                                        <option value="0"<c:if test="${data.marital == 0}">selected="true"</c:if>>未婚</option>
                                        <option value="1"<c:if test="${data.marital == 1}">selected="true"</c:if>>已婚</option>
                                        </select>
                                    </div>
                                </div>
                                <c:if test="${type==0}">
                                    <div class="form-group"><label class="col-sm-2 control-label">人群分类</label>
                                        <div class="col-sm-6 select-role-box">
                                            <select id="selectRole" class="select2_role form-control"  multiple="multiple" disabled readonly>
                                                <c:forEach var="items" items="${crowds}">
                                                    <option value="${items.id}">${items.title}</option>
                                                </c:forEach>
                                            </select>
                                        </div>
                                    </div>
                                </c:if>
                                <div class="form-group"><label class="col-sm-2 control-label"><span class="text-danger"></span>企业名称</label>
                                    <div class="col-sm-8"><input type="text" class="form-control" placeholder="请输入企业名称" value="${company}"  required readonly></div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>工号</label>
                                    <div class="col-sm-3"><input type="text" class="form-control" placeholder="请输入工号" onBlur="validate(this.value);" value="${data.workno}" id="workno" name="workno" required></div>

                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>所属部门</label>
                                    <div class="col-sm-3"><select name="deptId"  class="form-control form-filter"  style="width:100%" required>
                                        <option value="">请选择部门</option>
                                        <c:forEach items="${dept}" var="item">
                                          <option value="${item.id}" <c:if test="${item.id==data.deptId}">selected="true"</c:if>  >${item.title}</option>
                                        </c:forEach>
                                    </select></div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><span class="text-danger"></span>职务</label>
                                    <div class="col-sm-3"><input type="text" class="form-control" placeholder="请输入职务" value="${data.job}" name="job"></div>

                                    <label class="col-sm-2 control-label"><span class="text-danger">*</span>在职状态</label>
                                    <div class="col-sm-3">
                                        <select name="jstatus"  class="form-control form-filter"  style="width:100%" required>
                                            <option value="">请选择在职状态</option>
                                            <option value="0"<c:if test="${data.jstatus == 0}">selected="true"</c:if>>在职</option>
                                            <option value="1"<c:if test="${data.jstatus == 1}">selected="true"</c:if>>退休</option>
                                            <option value="2"<c:if test="${data.jstatus == 2}">selected="true"</c:if>>离职</option>
                                        </select>
                                    </div>
                                </div>
<c:if test="${!sys_flag}">
                                <div class="form-group"><label class="col-sm-2 control-label"><span class="text-danger">*</span>激活状态</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" placeholder="激活状态" value="
                        <c:choose><c:when test="${data.appStatus == 0}">未激活 </c:when>
                        <c:when test="${data.appStatus == 1}"> 已登陆</c:when>
                        <c:otherwise> 未激活</c:otherwise></c:choose>" required readonly>
                                        <input  type="hidden" name="appStatus" value="${data.appStatus}"/>
                                    </div>
                                </div>
</c:if>
                                <div class="hr-line-dashed"></div>
                                <div class="form-group">
                                    <div class="col-sm-4 col-sm-offset-2">
<c:if test="${sys_flag}">
    <button class="btn btn-primary" type="button" onclick="save()">保 存</button>
</c:if>
                                        <a href="javascript:history.go(-1);" class="btn btn-white ">  返回</a>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
<script type="text/javascript" src="${ctx}/static/inspinia/js/plugins/LD.sot/multiupf/uploadify2/jquery.uploadify.min.js"></script>
<script type="text/javascript" src="${ctx}/static/inspinia/js/plugins/LD.sot/multiupf/uploadify2/swfobject.js"></script>
<script type="text/javascript" src="${ctx}/static/inspinia/js/plugins/LD.sot/multiupf/multiupf.uploadify2.js"></script>
<script>
    var id ;
    var flag = false;
    var idvardflag = false;
    $(document).ready(function() {
        init_src();
        id = $("#ids").val();
        if (id == '' || id == undefined) {
            id = 0;
        }
        var select2_role =  $(".select2_role").select2();
        <c:if test="${data.id !=null}">
        var rids="${rids}";
        select2_role.val(eval("(["+rids+"])")).trigger('change');
        </c:if>

        var type = ${type};
        if(type == 0){
            flag = true;
            idvardflag = true;
        }
    });

    function init_src() {
        init_uploader('uploaderLogoUrl', 'srcView', 'src');
    }
    function init_uploader(id, view_id, url_id,del_btn) {
        $('#'+id).multiupf({
            uploader: '${image_upload_url}',
            fileExts: '*.png;*.jpg;', fileDesc: '*.png;*.jpg;',
            progress: function (data, queue) {
                if (queue.indexOf(id) > -1) {
                    $('#'+view_id).html("上传中...");
                }
            },
            complete: function (result, queue) {
                var url = result.data[0];
                if (queue.indexOf(id) > -1) {
                    $('#'+view_id).html('<img data-img src="' + url + '"  width="100%" height="100%">');
                    $('#'+url_id).val(url);
                    $("#"+del_btn).show();
                }
            }
        });
    }


    <%--function resetPass() {--%>
        <%--parent.layer.confirm('是否确认重置密码？', function() {--%>
            <%--$.ajax({--%>
                <%--url: "${ctx}/admin/ehm/user/resetPass",--%>
                <%--method: "POST",--%>
                <%--data: {username : "${data.username}"},--%>
                <%--dataType: "json",--%>
                <%--success : function(response) {--%>
                    <%--if (response.success) {--%>
                        <%--parent.layer.alert('重置成功');--%>
                    <%--} else {--%>
                        <%--parent.layer.alert('重置失败');--%>
                    <%--}--%>
                <%--}--%>
            <%--});--%>
        <%--})--%>
    <%--}--%>

    function save() {
        var b = true;

        if(!flag){
            var a = $("#workno").val();
            if(a == null || a == undefined || a == ''){
                parent.layer.msg('请输入工号');
            }else{
                parent.layer.msg('工号错误');
            }

            return;
        }
        if(!idvardflag){
            parent.layer.msg('身份证错误');
            return;
        }

        $("#selectRole").removeAttr("disabled");
        if (b) {
            $("#user_form").submit();
        }
    }

    function idcards(val) {
        if(val == '' || val == undefined){
            parent.layer.msg('请输入身份证号');
            console.log(1)
            return;
        }else  if(val.length == 15 || val.length == 18){
            console.log(2)
            $.ajax({
                method: "POST",
                url: "${ctx}/admin/ehm/user/cardinfo",
                data: {
                    card:val
                },
                dataType: "json",
                async: false,
                success: function(response) {
                    if (response.code == 0) {
                        idvardflag = true;
                       if(response.data!=null){
                           $("#uid").val(response.data.id);
                           $("#title").val(response.data.title);
                           $("#age").val(response.data.age);
                           if(response.data.sex!=null && response.data.sex == 1){
                               $("#sex").val("1");
                           }else if(response.data.sex!=null && response.data.sex == 2){
                               $("#sex").val("2");
                           }
                       }
                    }else{
                        idvardflag = false;
                        parent.layer.msg(response.msg);
                    }
                }
            });
        }else{
            console.log(3)
            parent.layer.msg('身份证格式错误');
            return;
        }

    }

    function validate(val) {
        if(val == '' || val == undefined){
            parent.layer.msg('工号');
            return;
        }else{
            $.ajax({
                method: "POST",
                url: "${ctx}/admin/ehm/user/validations",
                data: {
                    validation:val,
                    id:id
                },
                dataType: "json",
                async: false,
                success: function(response) {
                    if (response.code == 0) {
//                        parent.layer.msg('可以使用该工号');
                        flag = true;
                    }else{
                        flag = false;
                        parent.layer.msg('工号以被占用');
                    }
                }
            });
        }

    }

</script>
</body>

</html>
